// pages/partner/userList/userList.js
var app = getApp();
var pageSize = 20;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    count: 0,
    empty: false,
    loadmore: false,
    nomore: false,
    list: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.equipment_id = options.equipment_id;
    this.page = 1;
    this.getUserList();
  },





  getUserList() {
    app.ajax({
      url: "Partner/Equipment/user_list",
      data: {
        equipment_control_id: this.equipment_id,
        page: this.page,
        pageSize: pageSize,
      },
      success: res => {
        wx.stopPullDownRefresh()
        if (res.data.code > 0) {
          const {
            count,
            order: source
          } = res.data.data;
          let list = this.data.list.concat(source);
          console.log(list)
          this.setData({
            count,
            list,
            empty: count == 0 ? true : false,
            loadmore: list.length < count ? true : false,
            nomore: list.length >= count ? true : false
          })
        } else {
          app.showToast(res.data.message);
        }
      },
      error: e => {
        wx.stopPullDownRefresh()
        app.showToast("网络错误");
      }
    })
  },


  /*** 页面相关事件处理函数--监听用户下拉动作*/
  onPullDownRefresh: function () {
    this.page = 1;
    this.setData({
      list: [],
    })
    this.getUserList(); // 获取订单列表
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (!this.data.nomore) {
      this.page = this.page + 1;
      this.getUserList();
    }
  },
})